<?php

class Application_Model_Proyek extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_proyek';
    
    public function proyekBaru($data)
    {
        $id = $this->insert($data);
        return $id;
    }
   
    public function proyekUpdate($data, $id)
    {
        $this->update($data, 'id_proyek = '.(int)$id);
    }
    
    public function getAllData()
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->joinLeft('tabel_status_proyek', 'tabel_status_proyek.id_status_proyek = tabel_proyek.id_status_proyek');
        
        $result = $this->fetchAll($select);
        if($result)
            return $result->toArray ();
        else
            return false;
    }
    
    public function getAllDataCategories($status_proyek)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->joinLeft('tabel_status_proyek', 'tabel_status_proyek.id_status_proyek = tabel_proyek.id_status_proyek')
               ->where('tabel_status_proyek.status_proyek = ?',$status_proyek);
        
        $result = $this->fetchAll($select);
        if($result)
            return $result->toArray ();
        else
            return false;
    }
    
    public function getAllDataSelect()
    {
        $db = Zend_Db_Table::getDefaultAdapter();
        $selectProyek = new Zend_Db_Select($db);
        $selectProyek->from($this->_name)
                     ->joinLeft('tabel_konsumen', 'tabel_konsumen.id_konsumen = tabel_proyek.id_konsumen');
        
        return $selectProyek;
    }
    
    public function getData($id)
    {
        $select = $this->select();
        $select->where('id_proyek = ?', $id);
               
        $result = $this->fetchRow($select);
        
        if($result)
            return $result->toArray();
        else
            return false;
        
    }
}

